package com.changli01.string.exer5;

import java.util.Scanner;

public class Login {

    public static void main(String[] args) {
        Customer [] customers = new Customer[3];
        customers[0] = new Customer("John", "123456");
        customers[1] = new Customer("Jane", "987654");
        customers[2] = new Customer("yuwen", "qweasd");

        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter your userName: ");
        String username1 = sc.next();
        System.out.println("Please enter your password: ");
        String password1 = sc.next();






        boolean found = false;
        int index = 0;
        for(int i = 0; i < customers.length; i++){
            if(username1.equals(customers[i].getUserName())){
                if(password1.equals(customers[i].getPassword())){
//                    System.out.println("Login Successful");
//                    System.out.println("Welcome " + customers[i].getUserName());
                    found = true;
                    index = i;

                    break;
                }
                else {
//                    System.out.println("Login Failed");
//                    System.out.println("Password is incorrect");
                    found = false;
                }
            }
            else {
//                System.out.println("Login Failed");
//                System.out.println("UserName is incorrect");
                found = false;
            }
        }
        if(found == false){
            System.out.println("Login Failed");
            System.out.println("UserName or Password is incorrect");
        }
        else {
            System.out.println("Login Successful");
            System.out.println("Welcome " + customers[index].getUserName());
        }


        sc.close();

    }
}
class Customer{
    private  String userName;
    private  String password;

    public Customer() {
    }

    public Customer(String userName, String password) {
        this.userName = userName;
        this.password = password;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "Customer{" +
                "userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}